home *** CD-ROM | disk | FTP | other *** search
- /* This is the HOPALONG program described in A. K. Dewdney's COMPUTER */
- /* RECREATION column in Scientific American. This and many other intriguing */
- /* can be found in "The Armchair Universe", published by W. H. Freeman and */
- /* Company, New York, 1988. */
- /* */
- /* Coded by James Britt, May, 1989. */
-
- #include"stdio.h"
- #include"graphic.h"
- #include"math.h"
- #define LTGREEN '\231'
- #define STOP '\003'
- #define LTBLUE '\232'
- #define RED '\034'
- /* #define X 'X' */
-
-
-
-
- main()
-
- char cyc;
- float a, b, c;
- int i, num, t, j, k, w, s;
- float xx, yy, com, x, y;
- int c1, c2, c3, temp;
-
- printf("%c%c%c", CLR, HOME, LTBLUE );
- printf("\n\n %cH O P A L O N G",RED);
- printf("\n\n%cThis program is from A. K. Dewdney's ",LTBLUE);
- printf("\n%cComputer Recreations %ccolumn
- in\n%cScientific",LTGREEN,LTBLUE,RED);
- printf(" American. %c",LTBLUE);
- printf("\n\nThe %cSTOP %ckey interrupts the \nitteration cycle",RED,LTBLUE);
- printf("to allow you\nto modify the parameters.");
- printf("\n\n\n%cUse STOP/RESTORE to quit.",RED);
- printf("\n\n %c(Hit any key)",LTGREEN);
-
- getchar();
-
- printf("%c%c%c", CLR, HOME, LTBLUE );
- printf("\n\n The program plots the equation ");
- printf("\n xx=y-sign(x)*[abs(b*x-c)]**0.5 ");
- printf("\n yy=a-x ");
- printf("\n x=xx ");
- printf("\n y=yy ");
- printf("\n\nSome suggested values: ");
- printf("\n a b c ");
- printf("\n -3.14 0.3 0.3 ");
- printf("\n 0.4 1 0 ");
- printf("\n 23 -0.4 100 ");
- printf("\n\nThe X, Y offsets allow you to shift");
- printf("\nthe screen location of the plotted");
- printf("\npoints. The distortion factor expands");
- printf("\nor contracts the plotted image.");
- printf("\n\n%c (Hit any key)",RED);
-
- getchar();
-
- printf("%c%c%c", CLR, HOME, LTBLUE );
- printf("\n\n\nColor cycle changes the color of");
- printf("\neach dot, cycling through red, green");
- printf("\nand blue. It makes for a very pretty");
- printf("\neffect.");
- printf("\n\n\n%cWell, have fun. And check out the book",LTGREEN);
- printf("\n%cThe Armchair Universe, %cby A.K. Dewdney.",RED, LTGREEN);
- printf("\n\n %cJames Britt, May 1989",LTBLUE);
- printf("\n\n %c(Hit any key)",RED);
-
- getchar();
-
- while() /* endless main body loop */
-
- printf("%c%c%c", CLR, HOME, RED);
- printf("\n Enter a, b, c: ");
- scanf("%f%f%f", &a, &b, &c);
- printf("\n Enter x and y offsets: ");
- scanf("%d%d", &j, &k);
- /* offsets the plotted points */
-
- printf("\n Enter distortion factor_\b");
- scanf("%f", &com);
- /* con is multiplied with x and y to expand or contract the plotted image */
-
- printf("\n\n Color cycle? (y/n): ");
- scanf("%c",&cyc);
-
-
- graphic(); /* allocates grafx memory */
- backgr(14,0); /* sets boarder and background colors */
- graphon();clrmap(0);
- c1=red; c2=blue; c3=green;
- colors(c1, c2, c3 ); /* sets colors for classes 1, 2, and 3 */
-
- x=0; y=0;
- i=1;
-
-
- while ()
-
- w=(int)(x*com); s=(int)(y*com);
- dot(j+w, k+s);
- setcol((i%3)+1);
-
- xx=y-(sgn(x)*sqrt(abs(b*x-c)));
-
- yy=a-x;
- x=xx; y=yy;
-
- i++;
-
-
-
- if (getc(STDIO)==STOP)
- graphoff();
- printf("%c%c%c\n\n\n", CLR, HOME, LTBLUE );
-
- printf("\nA = %3g",a);
- printf("\nB = %3g",b);
- printf("\nC = %3g",c);
-
- printf("\n\nEnter new A, B, C: ");
- scanf("%f%f%f",&a,&b,&c);
-
- printf("\n\nCurrent displacement = %d, %d",j,k);
- printf("\nEnter new displacement: ");
- scanf("%d%d",&j,&k);
- printf("\n\nCurrent distortion = %5g", com);
- printf("\nEnter new distortion = ");
- scanf("%f",&com);
- printf("\n\nColor cycle? (y/n): ");
- scanf("%c",&cyc);
-
- x=0; y=0; i=1;
- graphon();
- clrmap(0);
-
- /* end if-stop */
-
- if(cyc=='y')
- temp=c1; c1=c2; c2=c3; c3=temp;
- colors(c1,c2,c3);
-
-
- /* end inner while() */
-
- graphoff();
-
-
- /* end outer while() */
-
- /* end main() */
-
-
-
-